package hn.cch.log.log4j2;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.ConfigurationSource;
import org.apache.logging.log4j.core.config.Configurator;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

/**
 * @author CCH
 * @version 2018.05.23
 */
public class TestLog4j2 {

    //日志记录
    private static Logger logger = LogManager.getLogger(TestLog4j2.class);


    public static void main(String[] args) throws IOException {


        File file = new File("log4j2/log4j2.xml");
        System.out.println(file.getAbsoluteFile() + ":"+ file.exists());
        LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false);
        loggerContext.setConfigLocation(file.toURI());
        loggerContext.reconfigure();




        for (int i = 0; i < 10; i++) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            logger.error("error" + i);
        }

    }
}
